﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using DataForest.Utilities;
using DataForest.View.Dialogs;
using Microsoft.Win32;

namespace DataForest.ViewModel.Dialogs
{
    public class DialogService : IDialogService
    {
        
        bool? IDialogService.ShowDialog(OpenFileDialogModel model)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = model.Filter;
            dlg.Title = model.Title;
            bool? result = dlg.ShowDialog();
            model.FileName = dlg.FileName;
            return result;
        }

        bool? IDialogService.ShowDialog(SaveFileDialogModel model)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = model.Filter;
            dlg.Title = model.Title;
            bool? result = dlg.ShowDialog();
            model.FileName = dlg.FileName;
            return result;
        }

        bool? IDialogService.ShowDialog(MessageDialogModel model)
        {
            MessageBox.Show(model.Message, model.Title, MessageBoxButton.OK);
            return true;
        }

        bool? IDialogService.ShowDialog(ErrorMessageDialogModel model)
        {
            MessageBox.Show(model.Message, model.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            return true;
        }

        bool? IDialogService.ShowDialog(ConfirmMessageDialogModel model)
        {
            MessageBoxResult result = MessageBox.Show(model.Message, model.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Error);
            if (result == MessageBoxResult.Yes) { return true; }
            if (result == MessageBoxResult.No) { return false; }
            return null;
        }

        bool? IDialogService.ShowDialog(SplitValueDialogModel model)
        {
            SplitValueDialogView dlg = new SplitValueDialogView();
            dlg.DataContext = model;
            return dlg.ShowDialog();
        }

        bool? IDialogService.ShowDialog(ColumnNameDialogViewModel model)
        {
            DataForest.View.Dialogs.
            ColumnNameDialogView dlg = new ColumnNameDialogView();
            dlg.DataContext = model;
            return dlg.ShowDialog();
        }

        bool? IDialogService.ShowDialog(CSVDialogViewModel model)
        {
            CSVDialogView dlg = new CSVDialogView();
            dlg.DataContext = model;
            return dlg.ShowDialog();
        }

        bool? IDialogService.ShowDialog(ExcelDialogViewModel model)
        {
            ExcelDialogView dlg = new ExcelDialogView();
            dlg.DataContext = model;
            return dlg.ShowDialog();
        }

        bool? IDialogService.ShowDialog(ManualModel model)
        {
            ManualView view = new ManualView();
            if (File.Exists(model.BaseSource))
            {
                string path = Path.Combine(Directory.GetCurrentDirectory(), model.UriSource);
                view.Browser.Source = new Uri(path);
                view.Show();
            }
            return true;
        }

    }
}
